package com.jiedeng.dao;

import com.jiedeng.model.ProjectCorp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author 覃远龙
 * @ClassName: IProjectCorpRepository
 * @Description:
 * @date 2017/8/4 10:16
 */
public interface IProjectCorpRepository extends JpaRepository<ProjectCorp, Long> {

    List<ProjectCorp> findByCorpId(long corpId);

    List<ProjectCorp> findByCorpPropIdAndProjectId(long corpPropId, long projectId);
    List<ProjectCorp> findByCorpIdAndProjectId(long corpId, long projectId);

    List<ProjectCorp> findByProjectId(long projectId);

@Query(nativeQuery = true, value = " select tpc.* from t_project_corp tpc left JOIN " +
        " (select DISTINCT tcc.Corp_ID from t_check tc LEFT JOIN t_checkcount tcc on tc.ID = tcc.Check_ID " +
        " where tc.Task_ID = ?1 ) a on a.Corp_ID = tpc.Corp_ID " +
        " where tpc.Project_ID = ?2 and tpc.Corp_Prop_ID = ?3 " +
        " ORDER BY a.Corp_ID DESC ")
    List<ProjectCorp> findProjectCorpSQL(String taskId,long corpPropId, long projectId);
}
